package edu.towson.cis.cosc490.jpanne1.lab3;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ToDoListActivity extends Activity implements OnClickListener, OnLongClickListener{
	Button m_addButton;
	EditText m_editText;
	LinearLayout m_itemListView;
	int darkOrLight;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		initLayout();
		m_addButton.setOnClickListener(this);
		darkOrLight = 0;
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_to_do_list, menu);
		return true;
	}
	
	private void initLayout(){
		m_addButton = (Button) this.findViewById(R.id.button1);
		m_editText = (EditText) this.findViewById(R.id.editText1);
		m_itemListView = (LinearLayout) this.findViewById(R.id.toDoListView);
	}

	@Override
	public void onClick(View v) {
		String stringToDo = m_editText.getText().toString();
		ToDoItem toDoObject = new ToDoItem(stringToDo);
		TextView newItemTextView = new TextView(this);
		if(darkOrLight == 0){
			newItemTextView.setBackgroundColor(getResources().getColor(R.color.light));
			darkOrLight = 1;
		} else{
			newItemTextView.setBackgroundColor(getResources().getColor(R.color.dark));
			darkOrLight = 0;
		}
		newItemTextView.setText(toDoObject.getToDoItem());
		newItemTextView.setOnLongClickListener(this);
		m_itemListView.addView(newItemTextView);
		m_editText.setText(null);
	}
	
	public boolean onLongClick(View v){
		TextView tv = (TextView) v;
		String message = tv.getText().toString();
		Intent smsIntent = new Intent(Intent.ACTION_VIEW);
		smsIntent.putExtra("sms_body", "TO-DO List Item: "+ message);
		smsIntent.putExtra("address", "");
		smsIntent.setType("vnd.android-dir/mms-sms");
		startActivity(smsIntent);
		return false;
	}
}
